home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PartUtils.cpp
- Contains: Part utility functions & classes
- Written by: PartMaker
-
- Change History (most recent first):
-
- <2> 3/8/95 JS Updated to b1c13/c14
- <1> 2/2/95 RA first checked in
- <0> PartMaker source by Eric Soldan, Tantek Çelik, Jens Alfke, Reggie Adkins
- */
-
- #ifndef _ALTPOINT_
- #include <AltPoint.h> /* Must come before other OpenDoc includes */
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _ODTYPES_
- #include <ODTypes.h> // MUST BE BEFORE TOOLBOX INCLUDES
- #endif
-
- #ifndef _CPPROCESSMAP_
- #include "CPProcessMap.h"
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef _PARTUTILS_
- #include "PartUtils.h"
- #endif
-
-
- #ifdef applec
- #pragma segment ProcessMap
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // MyDialogFilter
- //----------------------------------------------------------------------------------------
-
- pascal Boolean MyDialogFilter(DialogPtr dialog, EventRecord* event, short* itemHit)
- {
- ODBoolean handled = kODFalse;
-
- if (event->what == nullEvent ||
- event->what == updateEvt && (WindowPtr) event->message != dialog ||
- event->what == activateEvt && (WindowPtr) event->message != dialog)
- {
- Environment *ev = somGetGlobalEnvironment();
- gSession->GetDispatcher(ev)->Dispatch(ev, (ODEventData*)event);
- }
- else if ((event->what == keyDown) || (event->what == autoKey))
- {
- #define kMyButtonDelay 8
- long waitTicks;
- short itemKind;
- Handle itemHandle;
- Rect itemRect;
- char key = (char)(event->message & charCodeMask);
- const char kReturnKey = 13;
- const char kEnterKey = 3;
- const char kEscKey = 27;
-
- switch(key)
- {
- case kReturnKey:
- case kEnterKey:
- *itemHit = ok;
- ::GetDialogItem(dialog, ok, &itemKind, &itemHandle, &itemRect);
- ::HiliteControl((ControlHandle)itemHandle, kInButtonControlPart);
- ::Delay(kMyButtonDelay, &waitTicks);/* wait about 8 ticks */
- HiliteControl((ControlHandle)itemHandle, kODFalse);
- handled = kODTrue;
- break;
- case kEscKey:
- *itemHit = cancel;
- ::GetDialogItem(dialog, cancel, &itemKind, &itemHandle, &itemRect);
- ::HiliteControl((ControlHandle)itemHandle, kInButtonControlPart);
- ::Delay(kMyButtonDelay, &waitTicks);
- HiliteControl((ControlHandle)itemHandle, kODFalse);
- handled = kODTrue;
- break;
- }
- }
-
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // GetWindowPoint
- //----------------------------------------------------------------------------------------
-
- void GetWindowPoint(ODWindow *w, Environment *ev,
- Point globalPoint,
- ODPoint *localPoint)
- {
- GrafPtr curPort;
- ::GetPort(&curPort);
- ::SetPort(w->GetPlatformWindow(ev));
- ::SetOrigin(0,0);
- ::GlobalToLocal(&globalPoint);
- ::SetPort(curPort);
- *localPoint = globalPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // AreTraceKeysDown
- //----------------------------------------------------------------------------------------
-
- Boolean AreTraceKeysDown()
- {
- // test if Control and Option key are both down. Used for toggling EnteringMethod()
- union
- {
- KeyMap asMap;
- Byte asBytes[16];
- };
-
- const short kOptionKey = 58;
- const short kControlKey = 0x3B;
- ::GetKeys(asMap);
- return (asBytes[kOptionKey >> 3] & (1 << (kOptionKey & 0x07))) &&
- (asBytes[kControlKey >> 3] & (1 << (kControlKey & 0x07)));
- }
-